$(function () {
    renderRecruit().then(() => {
        $(".read_more").click(function () {
            let $item = $(this).parent()
            let $item_title = $item.children(".recruit_title")
            let $item_content = $item.children(".recruit_content")
            let $height = $item_title.innerHeight() + ($item.outerHeight() - $item.height()) + $item_content.outerHeight()
            $item.toggleClass("recruit_active")
            if ($item.hasClass("recruit_active")) {
                $item.css("height", $height + "px")
                $item.find(".read_tips_img").attr("src","/static/img/read_more_img.png")
            } else {
                $item.css("height", "100px")
                $item.find(".read_tips_img").attr("src","/static/img/read_more.png")
            }
        })
    })
    function renderRecruit() {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/api/getRecruit",
                type: "get",
                success: function (res) {
                    if (res.code == 200) {
                        let dom = ``
                        res.result = res.result || []
                        res.result.forEach(item => {
                            dom += `
                        <div class="recruit_item">
                            <div class="recruit_title">
                                <div class="recruit_name black_text">职位 : ${item.position}</div>
                                <div class="recruit_name black_text">发布日期 : ${item.releaseDate}</div>
                            </div>
                            <div class="recruit_content">${item.content}</div>
                            <div class="read_more">
                                <img src="/static/img/read_more.png" alt="" class="read_tips_img">
                            </div>
                        </div>
                        `
                        })
                        $(".recruit_list").html(dom)
                        resolve()
                    } else {
                        reject()
                    }
                }
            })
        })
    }
})